/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package contatospro;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Junnyor S2 Rafa
 */
@Entity
@Table(name = "emails", catalog = "contatospro", schema = "")
@NamedQueries({
    @NamedQuery(name = "Emails.findAll", query = "SELECT e FROM Emails e"),
    @NamedQuery(name = "Emails.findByCodEmail", query = "SELECT e FROM Emails e WHERE e.codEmail = :codEmail"),
    @NamedQuery(name = "Emails.findByCodPessoa", query = "SELECT e FROM Emails e WHERE e.codPessoa = :codPessoa"),
    @NamedQuery(name = "Emails.findByEmail", query = "SELECT e FROM Emails e WHERE e.email = :email"),
    @NamedQuery(name = "Emails.findByPrincipal", query = "SELECT e FROM Emails e WHERE e.principal = :principal")})
public class Emails implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "COD_EMAIL")
    private Integer codEmail;
    
    @JoinColumn(name = "COD_PESSOA",referencedColumnName="COD_PESSOA")
    @ManyToOne
    private Pessoas codPessoa;
    @Basic(optional = false)
    @Column(name = "EMAIL")
    private String email;
    @Column(name = "PRINCIPAL")
    private String principal;

    public Emails() {
    }

    public Emails(Integer codEmail) {
        this.codEmail = codEmail;
    }

    public Emails(Integer codEmail, Pessoas codPessoa, String email) {
        this.codEmail = codEmail;
        this.codPessoa = codPessoa;
        this.email = email;
    }

    public Integer getCodEmail() {
        return codEmail;
    }

    public void setCodEmail(Integer codEmail) {
        Integer oldCodEmail = this.codEmail;
        this.codEmail = codEmail;
        changeSupport.firePropertyChange("codEmail", oldCodEmail, codEmail);
    }

    public Pessoas getCodPessoa() {
        return codPessoa;
    }

    public void setCodPessoa(Pessoas codPessoa) {
        Pessoas oldCodPessoa = this.codPessoa;
        this.codPessoa = codPessoa;
        changeSupport.firePropertyChange("codPessoa", oldCodPessoa, codPessoa);
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        String oldEmail = this.email;
        this.email = email;
        changeSupport.firePropertyChange("email", oldEmail, email);
    }

    public String getPrincipal() {
        return principal;
    }

    public void setPrincipal(String principal) {
        String oldPrincipal = this.principal;
        this.principal = principal;
        changeSupport.firePropertyChange("principal", oldPrincipal, principal);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codEmail != null ? codEmail.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Emails)) {
            return false;
        }
        Emails other = (Emails) object;
        if ((this.codEmail == null && other.codEmail != null) || (this.codEmail != null && !this.codEmail.equals(other.codEmail))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "contatospro.Emails[ codEmail=" + codEmail + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
